package com.ffms.service.impl;


import com.ffms.dao.*;

import com.ffms.dao.impl.*;

import com.ffms.entity.*;


import com.ffms.service.AdminService;

import java.sql.SQLException;
import java.util.List;

public class AdminServiceImpl implements AdminService {
    private AdminDao adminDao = new AdminDaoImpl();
    private FamilyMemberDao familyMemberDao = new FamilyMemberDaoImpl();
    private BankDao bankDao = new BankDaoImpl();
    private ShouruDao shouruDao = new ShouruDaoImpl();
    private ZhiChuDaoImpl zhiChuDaoImpl = new ZhiChuDaoImpl();

    public AdminDao getAdminDao() {
        return adminDao;
    }

    public void setAdminDao(AdminDao adminDao) {
        this.adminDao = adminDao;
    }

    @Override
    public Admin login(String userId, String password) {
        //AdminDao adminDao = new AdminDaoImpl();
        Admin admin = adminDao.findAdmin(userId, password);
        return admin;
    }

    @Override
    public Admin loginByName(String username) {
        //AdminDao adminDao = new AdminDaoImpl();
        Admin admin = adminDao.findAdminByName(username);
        return admin;
    }

    @Override
    public Admin loginBypwd(String password) {
        Admin admin = adminDao.findAdminBypwd(password);
        return admin;
    }

    @Override
    public int register(Admin admin) {
        return this.adminDao.save(admin);
    }

    @Override
    //查询所有家庭成员
    public List<FamilyMember> findAllMember() {
        return familyMemberDao.findAll();
    }

    @Override
    public int addFm(FamilyMember fm) {
        return this.familyMemberDao.save(fm);
    }

    //删除成员
    @Override
    public void deleteFM(String name) {
        try {
            this.familyMemberDao.delete(name);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

    //根据姓名找成员
    @Override
    public FamilyMember findFMByName(String name) {
        return this.familyMemberDao.findByName(name);
    }

    // 更新admin信息
    @Override
    public int updateAd(Admin ad) {
        return this.adminDao.update(ad);
    }

    //更新成员信息
    @Override
    public int updateFM(FamilyMember fm) {
        return this.familyMemberDao.update(fm);
    }

    //添加银行账户
    @Override
    public int addBank(Bank bank) {
        return this.bankDao.save(bank);

    }

    @Override
    public List<Shouru> findshouru() {
        return this.shouruDao.shouru();
    }

    @Override
    public List<ZhiChu> findzhihchu() {
        return zhiChuDaoImpl.zhuchu();
    }

    @Override
    public List<Shouru> findshouruByMid(int sid) {
        return shouruDao.shouruByMid(sid);
    }

    @Override
    public List<ZhiChu> findzhihchuByMid(int sid) {
        return zhiChuDaoImpl.zhuchuByMid(sid);
    }
}
